﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using ZF.BLL;
using System.Linq.Expressions;
using ZF.BLL;
using System.Linq.Expressions;
using GCELibrary.Current;
using ZF.BLL.Linq;
using GCELibrary.Current;
using ZF.Model;
namespace ZF.WS.expert
{
    public partial class artList : BLL.Page.PageBase
    {
        public Model.US_Member Expert { get; set; }
        public string EType
        {
            get
            {
                return DictionaryConfig.EExpertType.FirstOrDefault(p => p.Key == Expert.ExpertType).Text;
            }
        }
        [PageArgument(Key = "id", CanNull = false)]
        public int Id { get; set; }

        public static Random Random = new Random();
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                Expert = dc.US_Member.FirstOrDefault(p => p.MemberId == Id && p.IsExpert);

                if (Expert == null)
                {
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                }
                Expert.E_Article.Load();
    


                Dictionary<int, ArticleType[]> atsDic = new Dictionary<int, ArticleType[]>();

                atsDic[1] = new ArticleType[] { ArticleType.我的文章, ArticleType.学术研究, ArticleType.案例分析, };//风水师
                atsDic[2] = new ArticleType[] { ArticleType.我的文章, ArticleType.设计理念, ArticleType.设计案例, };//设计师
                atsDic[3] = new ArticleType[] { ArticleType.我的文章, };//地产顾问
                atsDic[4] = new ArticleType[] { ArticleType.我的文章, ArticleType.合作银行, ArticleType.贷款种类, };//房货顾问

                var atIds = atsDic[Expert.ExpertType].Select(p => (int)p).ToArray();


                var artList = Expert.E_Article.Where(p => atIds.Contains(p.Type)).ToList();
                Dictionary<ArticleType, object> dicObj = new Dictionary<ArticleType, object>();


                var artGroup = atIds.Select(p => new
                {
                    Key = p.Convert<ArticleType>(),
                    Value = artList.Where(a => a.Type == p).ToList()

                }).ToList();

                this.lvArtList.DataSource = artGroup;
                this.lvArtList.DataBind();

                this.lvArtList1.DataSource = artGroup;
                this.lvArtList1.DataBind();

            }

        }
    }
}
